/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.toools.gwt.wmc.client.disposer.gui;

import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.Collection;
import org.toools.gwt.widget.client.bc.BasicControl;
import org.toools.gwt.widget.client.bc.BasicList;
import org.toools.gwt.widget.client.bc.BasicListener;
import org.toools.gwt.widget.client.bc.BusinessObjectPanel;
import org.toools.gwt.widget.client.cloud.TagVO;
import org.toools.gwt.wmc.client.disposer.DisposerServiceAsync;
import org.toools.gwt.wmc.jpa.Container;
import org.toools.gwt.wmc.jpa.Disposer;
import org.toools.gwt.wmc.jpa.Waste;

/**
 *
 * @author Manuel
 */
public class DisposerControl extends BasicControl{

    public DisposerControl(DisposerServiceAsync service) {
        super(service, new org.toools.gwt.widget.client.util.Account());
        service.getDisposers(new AsyncCallback<Collection<Disposer>>() {
                public void onSuccess(Collection<Disposer> result) {
                    System.out.println("Disposers loaded");
                    TagVO[] tags = DisposerControl.this.getTagVO(result.toArray());
                    DisposerControl.this.setTags(tags);
                    DisposerControl.this.clearStatus();
                    DisposerControl.this.setStatus( DisposerControl.this.getLoadedMessage());
                    DisposerControl.this.getCreateList().clear();
                }

                public void onFailure(Throwable t) {
                    DisposerControl.this.setStatus( "Failure on loading Disposers");
                    DisposerControl.this.getDefaultCreateTogglePanel().setVisible(false);
                    DisposerControl.this.getCloudFilter().setVisible(false);
                }

                public String getOnFailureMessage(Throwable t) {
                    System.out.println("" + t);
                    return "Error while loading. Contact your administrator: " + new java.util.Date().getTime();
                }
        });
    }

    public BusinessObjectPanel createBasicPanel(Object o) {
        return new DisposerPanel(o);
    }
    public BasicListener createBasicListener() {
        return new DisposerListener(this);
    }
    public BasicList createBasicList() {
        DisposerList al = new DisposerList(new TagVO[]{}, this);
        return al;
    }
    public TagVO getTagVO(Object bp) {
        Disposer c = (Disposer) bp;
        TagVO result = new TagVO("" + c.getId(), c.getName(), 0, 0);
        result.setAttachedBusinessObject(c);
        return result;
    }
    @Override
    public String getFilterMessage() {
        return "search by name";
    }
    @Override
    public String getTitle() {
        return "Disposers";
    }
    @Override
    public void addSortItem() {
        getSortListBox().clear();
        getSortListBox().addItem("name");
    }
}
